﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IndexNote.aspx.cs" Inherits="DATN.mds.Note.IndexNote" MasterPageFile="~/InternalSite.Master" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent1" runat="server">
    <script type="text/javascript">
    //Reference of the GridView. 
    var TargetBaseControl = null;
    //Total no of checkboxes in a particular column inside the GridView.
    var CheckBoxes;
    //Total no of checked checkboxes in a particular column inside the GridView.
    var CheckedCheckBoxes;
    //Array of selected item's Ids.
    var SelectedItems;
    //Hidden field that wil contain string of selected item's Ids separated by '|'.
    var SelectedValues;

    window.onload = function () {
        //Get reference of the GridView. 
        try {
            TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>');
        }
        catch (err) {
            TargetBaseControl = null;
        }

        //Get total no of checkboxes in a particular column inside the GridView.
        try {
            CheckBoxes = parseInt('<%= this.GridView1.Rows.Count %>');
        }
        catch (err) {
            CheckBoxes = 0;
        }

        //Get total no of checked checkboxes in a particular column inside the GridView.
        CheckedCheckBoxes = 0;

        //Get hidden field that wil contain string of selected item's Ids separated by '|'.
        SelectedValues = document.getElementById('<%= this.hdnFldSelectedValues.ClientID %>');

        //Get an array of selected item's Ids.
        if (SelectedValues.value == '')
            SelectedItems = new Array();
        else
            SelectedItems = SelectedValues.value.split('|');

        //Restore selected CheckBoxes' states.
        if (TargetBaseControl != null)
            RestoreState();
    }

    function HeaderClick(CheckBox) {
        //Get all the control of the type INPUT in the base control.
        var Inputs = TargetBaseControl.getElementsByTagName('input');

        //Checked/Unchecked all the checkBoxes in side the GridView & modify selected items array.
        for (var n = 0; n < Inputs.length; ++n)
            if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkBxSelect', 0) >= 0) {
                Inputs[n].checked = CheckBox.checked;
                if (CheckBox.checked)
                    SelectedItems.push(document.getElementById(Inputs[n].id.replace('chkBxSelect', 'hdnFldId')).value);
                else
                    DeleteItem(document.getElementById(Inputs[n].id.replace('chkBxSelect', 'hdnFldId')).value);
            }

        //Update Selected Values. 
        SelectedValues.value = SelectedItems.join('|');

        //Reset Counter
        CheckedCheckBoxes = CheckBox.checked ? CheckBoxes : 0;
    }

    function ChildClick(CheckBox, HCheckBox, Id) {
        //Modifiy Counter;            
        if (CheckBox.checked && CheckedCheckBoxes < CheckBoxes)
            CheckedCheckBoxes++;
        else if (CheckedCheckBoxes > 0)
            CheckedCheckBoxes--;

        //Change state of the header CheckBox.
        if (CheckedCheckBoxes < CheckBoxes)
            HCheckBox.checked = false;
        else if (CheckedCheckBoxes == CheckBoxes)
            HCheckBox.checked = true;

        //Modify selected items array.
        if (CheckBox.checked)
            SelectedItems.push(Id);
        else
            DeleteItem(Id);

        //Update Selected Values. 
        SelectedValues.value = SelectedItems.join('|');
    }

    function RestoreState() {
        //Get all the control of the type INPUT in the base control.
        var Inputs = TargetBaseControl.getElementsByTagName('input');

        //Header CheckBox
        var HCheckBox = null;

        //Restore previous state of the all checkBoxes in side the GridView.
        for (var n = 0; n < Inputs.length; ++n)
            if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkBxSelect', 0) >= 0)
                if (IsItemExists(document.getElementById(Inputs[n].id.replace('chkBxSelect', 'hdnFldId')).value) > -1) {
                    Inputs[n].checked = true;
                    CheckedCheckBoxes++;
                }
                else
                    Inputs[n].checked = false;
            else if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkBxHeader', 0) >= 0)
                HCheckBox = Inputs[n];

        //Change state of the header CheckBox.
        if (CheckedCheckBoxes < CheckBoxes)
            HCheckBox.checked = false;
        else if (CheckedCheckBoxes == CheckBoxes)
            HCheckBox.checked = true;
    }

    function DeleteItem(Text) {
        var n = IsItemExists(Text);
        if (n > -1)
            SelectedItems.splice(n, 1);
    }

    function IsItemExists(Text) {
        for (var n = 0; n < SelectedItems.length; ++n)
            if (SelectedItems[n] == Text)
                return n;

        return -1;
    }     
    </script>

  </asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent2" runat="server">
    <div id="contentx" class="clearingfix">
                    <center>
                            <br/>
                        <h3>Qu&#7843;n lý Ghi Chú</h3>
                        <hr/>
                    </center>
              <div class="floatboxinternal">
              <center>


<b>Tìm Ki&#7871;m Ghi Chú:</b>

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" CssClass="bty" 
                      onselectedindexchanged="DropDownList1_SelectedIndexChanged" 
                      Width="148px">
                  </asp:DropDownList>
&nbsp;<asp:GridView ID="GridView1" runat="server" 
        RowStyle-CssClass = "Grd_Row"
        CssClass = "gridviewcss" 
        AllowPaging ="true" 
        onrowcommand="GridView1_RowCommand" 
        onrowdatabound="GridView1_RowDataBound" 
        AutoGenerateColumns ="false" 
        onpageindexchanging="GridView1_PageIndexChanging" 
        onrowdeleting="GridView1_RowDeleting"
        CellPadding="2" 
        ForeColor="Black" GridLines="Vertical"  BackColor="White" 
        BorderColor="#90abb8" BorderStyle="None" BorderWidth="1px"
        HeaderStyle-Height="20px" EmptyDataText ="Không có k&#7871;t qu&#7843; nào c&#7843;." EmptyDataRowStyle-ForeColor="Red"
        EmptyDataRowStyle-HorizontalAlign="Center" AllowSorting="True" onsorting="SortButton_Click"
        EmptyDataRowStyle-Font-Size="X-Large">


        <AlternatingRowStyle BackColor="#DCDCDC" />
        <Columns>

         <asp:TemplateField HeaderText="">
                     <ItemTemplate>
                        <asp:CheckBox ID="chkBxSelect" runat="server" />
                        <asp:HiddenField ID="hdnFldId" runat="server" Value='<%# Eval("No_Id") %>' />
                     </ItemTemplate>
                     <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                     <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                     <HeaderTemplate>
                        <center><asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server" />
                        </center>
                     </HeaderTemplate>
                  </asp:TemplateField>

         

            <asp:BoundField DataField="Name" HeaderText="Tên Ghi Chú" SortExpression="Name">
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
            </asp:BoundField>

            <asp:BoundField DataField="Description" HeaderText="N&#7897;i Dung">
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
            </asp:BoundField>

            <asp:BoundField DataField="TimeRemind" HeaderText="Th&#7901;i Gian" SortExpression="TimeRemind"
                            DataFormatString="{0:dddd' 'dd'/'MM'/'yyyy hh':'mm':'ss}">
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
            </asp:BoundField>

            <asp:TemplateField>
                <HeaderTemplate>Thao Tác</HeaderTemplate>
                <ItemTemplate>
                   <asp:LinkButton ID="LinkButton2" 
                                   CommandArgument='<%# Eval("No_Id") %>' 
                                   CommandName="Edit" runat="server">
                                    S&#7917;a</asp:LinkButton>
                    |
                   <asp:LinkButton ID="LinkButton1" 
                                   CommandArgument='<%# Eval("No_Id") %>' 
                                   CommandName="Delete" runat="server">
                                    Xóa</asp:LinkButton>
                   
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
            </asp:TemplateField>
        </Columns>


         <FooterStyle BackColor="#004a96" />
                <FooterStyle BackColor="#004a96" />
                <HeaderStyle BackColor="#004a96" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#004a96" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#b4cbd5" ForeColor="Black" Font-Size= "Small" />
                <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />

                <SortedAscendingCellStyle BackColor="#FBFBF2" />
                <SortedAscendingHeaderStyle BackColor="#848384" />
                <SortedDescendingCellStyle BackColor="#EAEAD3" />
                <SortedDescendingHeaderStyle BackColor="#575357" />
    </asp:GridView>

    <asp:HiddenField ID="hdnFldSelectedValues" runat="server" />

    <br/>
    <asp:Button ID="Create" runat="server" onclick="Create_Click" 
        Text="T&#7841;o M&#7899;i Ghi Chú" CssClass="bty" />
                   
    <asp:Button ID="btnCheckBox" runat="server" Text="Xóa Ghi Chú" 
        CssClass="bty" onclick="btnCheckBox_Click" />
    
    <asp:Label ID="lb_IdCheckBox" runat="server" Text=""></asp:Label>
      </center>
        
        </div>
        </div>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent3" runat="server">
  
</asp:Content>
